Skip to content

Drop unread data from .cmt files - #9252

Open
cknitt wants to merge 3 commits into
masterfrom
cmt-value-deps-locations
Open

cknitt wants to merge 3 commits into
masterfrom
cmt-value-deps-locations

Conversation

@cknitt

@cknitt cknitt commented Nov 6, 2026

Copy link
Copy Markdown
Member

Drops data that no tool reads from .cmt/.cmti files. Follow-up to the artifact-size findings in #9148.

  1. Value dependencies as two locations and a flag. Each value inclusion check stored both full Types.value_descriptions (type, attributes, doc comments). Reanalyze, the only reader, uses the two locations and whether both types take optional arguments, so that's all the compiler records now. The flag is decided when the .cmt is written, as before, when the types were marshalled at that point.
  2. Unread cmt_infos fields removed. cmt_comments (always empty), cmt_args, cmt_sourcefile, cmt_builddir, cmt_loadpath, cmt_initial_env, cmt_imports and cmt_use_summaries were write-only. The OCAML_BINANNOT_WITHENV switch is removed as well. What's left: module name, typed tree, value dependencies, source digest (rescript-tools migrate) and deprecation uses.
  3. Env.summary removed. Every env extension prepended a summary node, and .cmt files kept these logs in every typed-tree environment. OCaml tools replay them through Envaux, which this compiler doesn't have. The envs stored in .cmt files now keep only their GADT local constraints and flags. Reanalyze and gentype only look things up in those envs, and those lookups read tables that were already empty in .cmt files.

Runtime artifacts, master → this PR:

master PR change
.cmt total 4.07 MB 3.05 MB −25%
.cmti total 1.24 MB 1.12 MB −9%
Stdlib_Array.cmt 195 KB 102 KB −48%

.cmi files are unchanged. On 54 Belt and tests/tests files, the generated JS is byte-identical and allocation is 0.2% lower.

No magic-number bump, per compiler/AGENTS.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gLMbg8G3FeSq6sPLM2

cknitt and others added 3 commits November 6, 2026 21:26
Why:
    Each value inclusion check stored both full value descriptions (type,
    attributes, doc comments) in the .cmt, a fifth of the stdlib's .cmt
    bytes. Reanalyze, the only reader, uses the two locations and whether
    both types take optional arguments; the compiler now records just that.

Review: Does reanalyze still see the same optional-argument references?
Yes: the flag is computed with the same check on the same two types, the
deadcode snapshots are unchanged, and forcing the flag off adds three
findings to them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gLMbg8G3FeSq6sPLM2
Signed-off-by: Christoph Knittel <ck@cca.io>
Why:
    Eight cmt_infos fields came from OCaml and had no reader: the comments
    (always empty), the command line, source file, build directory, load
    path, initial environment, imports and the use_summaries flag.
    Dropping them and the OCAML_BINANNOT_WITHENV switch (which kept full
    environments in the typed tree) leaves the module name, the typed
    tree, the value dependencies, the source digest (rescript-tools
    migrate) and the deprecation uses. The runtime's .cmt and .cmti files
    get 3% smaller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gLMbg8G3FeSq6sPLM2
Signed-off-by: Christoph Knittel <ck@cca.io>
Why:
    Every environment extension also prepended a summary node (a log of
    the bindings and opens that built it), and .cmt files kept these logs
    in every environment of the typed tree. OCaml tools replay them with
    Envaux to rebuild an environment; this compiler has no Envaux and no
    tool reads them. The environments stored in .cmt files now keep only
    their GADT local constraints and flags, and the runtime's .cmt and
    .cmti files get 7% smaller.

Review: Do reanalyze and gentype lose anything? No: they only look types
and modules up in typed-tree environments, and the tables those lookups
read were already empty in .cmt files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gLMbg8G3FeSq6sPLM2
Signed-off-by: Christoph Knittel <ck@cca.io>
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Changelog

🏠 Internal

  • Write a quarter less into .cmt files by dropping data no tool reads (full value descriptions in the value dependencies, OCaml-only fields, environment summaries).

Semantic Diff

3 commits · Full page

Record value dependencies in .cmt files as two locations and a flag

bc2f41b · cknitt + Claude · Nov 06, 2026, 21:06 UTC

Why

Each value inclusion check stored both full value descriptions (type, attributes, doc comments) in the .cmt, a fifth of the stdlib's .cmt bytes. Reanalyze, the only reader, uses the two locations and whether both types take optional arguments; the compiler now records just that.

Review

  • Does reanalyze still see the same optional-argument references? Yes: the flag is computed with the same check on the same two types, the deadcode snapshots are unchanged, and forcing the flag off adds three findings to them.
Stop writing .cmt fields that no tool reads

5a289d9 · cknitt + Claude · Nov 06, 2026, 21:10 UTC

Why

Eight cmt_infos fields came from OCaml and had no reader: the comments (always empty), the command line, source file, build directory, load path, initial environment, imports and the use_summaries flag. Dropping them and the OCAML_BINANNOT_WITHENV switch (which kept full environments in the typed tree) leaves the module name, the typed tree, the value dependencies, the source digest (rescript-tools migrate) and the deprecation uses. The runtime's .cmt and .cmti files get 3% smaller.

Remove environment summaries

14fa937 · cknitt + Claude · Nov 06, 2026, 21:12 UTC

Why

Every environment extension also prepended a summary node (a log of the bindings and opens that built it), and .cmt files kept these logs in every environment of the typed tree. OCaml tools replay them with Envaux to rebuild an environment; this compiler has no Envaux and no tool reads them. The environments stored in .cmt files now keep only their GADT local constraints and flags, and the runtime's .cmt and .cmti files get 7% smaller.

Review

  • Do reanalyze and gentype lose anything? No: they only look types and modules up in typed-tree environments, and the tables those lookups read were already empty in .cmt files.

@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.74%. Comparing base (827be16) to head (14fa937).

Files with missing lines Patch % Lines
compiler/ml/cmt_format_common.ml 89.47% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9252   +/-   ##
=======================================
  Coverage   81.74%   81.74%           
=======================================
  Files         457      457           
  Lines       65713    65708    -5     
=======================================
- Hits        53715    53711    -4     
+ Misses      11998    11997    -1     
Files with missing lines Coverage Δ
analysis/reanalyze/src/dead_optional_args.ml 92.00% <100.00%> (ø)
analysis/reanalyze/src/dead_value.ml 85.95% <100.00%> (+0.06%) ⬆️
compiler/bsc/rescript_compiler_driver.ml 80.70% <ø> (-0.07%) ⬇️
compiler/core/js_implementation.ml 83.89% <100.00%> (ø)
compiler/ext/compiler_request_state.ml 93.75% <ø> (ø)
compiler/ml/cmt_format.ml 100.00% <100.00%> (ø)
compiler/ml/env.ml 79.27% <100.00%> (-0.10%) ⬇️
compiler/ml/typemod.ml 76.90% <ø> (ø)
tests/ounit_tests/ounit_compiler_request_tests.ml 97.07% <100.00%> (-0.02%) ⬇️
compiler/ml/cmt_format_common.ml 85.00% <89.47%> (+3.51%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Nov 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9252

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9252

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9252

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9252

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9252

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9252

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9252

commit: 14fa937

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

@cknitt

cknitt commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T06:05:46.722468Z 14fa937 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 14fa937d67

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt
cknitt marked this pull request as ready for review November 7, 2026 06:17
@cknitt
cknitt requested a review from cristianoc November 7, 2026 06:18

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant